﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;

namespace CSharpDataAccess.Product
{
    /// <summary>
    /// Defines the contract that clients implements to Log information
    /// </summary>
    /// <remarks>Factory Method: Product</remarks>
    public interface IDataAccessHandler
    {
        string StringConnection { get; set; }

        bool Open();
        bool Close();

        /// <summary>
        /// Executes the query, and returns the first column of the first row in the result set returned by the query. 
        /// </summary>
        /// <param name="commandType"></param>
        /// <param name="commandText"></param>
        /// <returns></returns>
        T ExecuteScalar<T>(CommandType commandType, string commandText);

        /// <summary>
        /// Executes a Transact-SQL statement against the connection and returns the number of rows affected.
        /// </summary>
        /// <see cref="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executenonquery(v=vs.100).aspx"/>
        /// <param name="commandType"></param>
        /// <param name="commandText"></param>
        /// <returns>For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. For all other types of statements, 
        /// the return value is -1. If a rollback occurs, the return value is also -1.</returns>       
        int ExecuteNonQuery(CommandType commandType, string commandText);

        /// <summary>
        /// Represents a set of data commands and a database connection that are used to fill the DataSet and update a SQL Server database.
        /// </summary>
        /// <param name="commandType"></param>
        /// <param name="commandText"></param>
        /// <returns></returns>
        DataSet ExecuteDataSet(CommandType commandType, string commandText);
        DataTable ExecuteDataTable(CommandType commandType, string commandText);

        /// <summary>
        /// Executes the CommandText against the Connection, and builds an IDataReader using one of the CommandBehavior values.
        /// </summary>
        /// <param name="commandBehavior"></param>
        /// <param name="commandText"></param>
        /// <returns></returns>
        IEnumerable<T> ExecuteDataReader<T>(CommandBehavior commandBehavior, string commandText, Func<IDataRecord,T> selector);
        IEnumerable<IDataRecord> ExecuteDataReader(CommandBehavior commandBehavior, string commandText);
    }
}
